package Practice;

import java.util.Scanner;

public class Canteen {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int a2 = sc.nextInt();
            int a3 = sc.nextInt();
            int a4 = sc.nextInt();
            int b4 = sc.nextInt();
            int b6 = sc.nextInt();
            int count = 0;
            while (b4 > 0 && a4 > 0) {//4=4
                b4--;
                a4--;
                count += 4;
            }
            while (a2 > 0 && a4 > 0 && b6 > 0) {//6=2+4
                a2--;
                a4--;
                b6--;
                count += 6;
            }
            while (a3 > 1 && b6 > 0) {//6=3+3
                a3 -= 2;
                b6--;
                count += 6;
            }
            while (a2 > 2 && b6 > 0) {//6=2+2+2
                a2 -= 3;
                b6--;
                count += 6;
            }
            while (a2>1&&b4>0) {//4=2+2
                a2 -= 2;
                b4--;
                count += 4;
            }
            while (a2>0&&a3>0&&b6>0) {//6>2+3
                a2--;
                a3--;
                b6--;
                count += 5;
            }
            while (a3>0&&b4>0) {//4>3
                a3--;
                b4--;
                count += 3;
            }
            while(b4>0&&a2>0)//4>2
            {
                a2--;
                b4--;
                count += 2;
            }
            while(b6>0&&a4>0)//6>4
            {
                a4--;
                b6--;
                count += 4;
            }
            while(b6>0&&a3>0)//6>3
            {
                a3--;
                b6--;
                count += 3;
            }
            while(b6>0&&a2>0)//6>2
            {
                a2--;
                b6--;
                count += 2;
            }
            System.out.println(count);
        }
        sc.close();
    }
}
